package com.wysql.ascost.controller.info;

import com.wysql.ascost.common.base.BaseController;
import com.wysql.ascost.common.domain.AjaxResult;
import com.wysql.ascost.common.domain.ResultTable;
import com.wysql.ascost.model.custom.Tablepar;
import com.wysql.ascost.model.info.InfoContractstore;
import com.github.pagehelper.PageInfo;
import com.wysql.ascost.service.info.InfoContractstoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 协议库存信息查询--主表Controller
 *
 * @author wysqlauto
 * @ClassName: InfoContractstoreController
 * @date 2025-03-10 15:10:54
 */
@Api(value = "协议库存信息查询--主表")
@Controller
@RequestMapping("/InfoContractstoreController")
public class InfoContractstoreController extends BaseController {

    private String prefix = "info/infoContractstore";

    @Autowired
    private InfoContractstoreService infoContractstoreService;


    /**
     * 协议库存信息查询--主表页面展示
     *
     * @param model
     * @return String
     * @author wysqlauto
     */
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/view")
    @RequiresPermissions("info:infoContractstore:view")
    public String view(ModelMap model) {
        return prefix + "/list";
    }

    /**
     * list集合
     *
     * @param tablepar
     * @param
     * @return
     */
    //@Log(title = "协议库存信息查询--主表", action = "111")
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/list")
    @RequiresPermissions("info:infoContractstore:list")
    @ResponseBody
    public ResultTable list(Tablepar tablepar, InfoContractstore infoContractstore) {
        PageInfo<InfoContractstore> page = infoContractstoreService.list(tablepar, infoContractstore);
        return pageTable(page.getList(), page.getTotal());
    }

    /**
     * 新增跳转
     */
    @ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap) {
        return prefix + "/add";
    }

    /**
     * 新增保存
     *
     * @param
     * @return
     */
    //@Log(title = "协议库存信息查询--主表新增", action = "111")
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/add")
    @RequiresPermissions("info:infoContractstore:add")
    @ResponseBody
    public AjaxResult add(InfoContractstore infoContractstore) {
        int b = infoContractstoreService.insertSelective(infoContractstore);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }

    /**
     * 协议库存信息查询--主表删除
     *
     * @param ids
     * @return
     */
    //@Log(title = "协议库存信息查询--主表删除", action = "111")
    @ApiOperation(value = "删除", notes = "删除")
    @DeleteMapping("/remove")
    @RequiresPermissions("info:infoContractstore:remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
//        int b = infoContractstoreService.deleteByPrimaryKey(ids);
        InfoContractstore infoContractstore = infoContractstoreService.selectByPrimaryKey(ids);
        infoContractstore.setIsdelete(1);
        int b = infoContractstoreService.updateByPrimaryKeySelective(infoContractstore);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }


    /**
     * 修改跳转
     *
     * @param id
     * @param
     * @return
     */
    @ApiOperation(value = "修改跳转", notes = "修改跳转")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map) {
        map.put("InfoContractstore", infoContractstoreService.selectByPrimaryKey(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    //@Log(title = "协议库存信息查询--主表修改", action = "111")
    @ApiOperation(value = "修改保存", notes = "修改保存")
    @RequiresPermissions("info:infoContractstore:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody InfoContractstore infoContractstore) {
        return toAjax(infoContractstoreService.updateByPrimaryKeySelective(infoContractstore));
    }

    @ResponseBody
    @RequestMapping(value = { "/uploadFile"})
    public Map<String, Object> uploadFile(MultipartFile file) throws Exception {
        return infoContractstoreService.uploadFile(file);
    }

    /**
     * 综合分析详情页跳转（行上按钮）
     *
     * @param id
     * @param
     * @return
     */
    @ApiOperation(value = "综合分析详情页跳转（行上按钮）", notes = "综合分析详情页跳转（行上按钮）")
    @GetMapping("/viewdtl/{id}")
    public String viewdtl(@PathVariable("id") String id, ModelMap map) {
        map.put("id", id);
        return prefix + "/viewdtl";
    }

}
